// 6.65 已知一棵二叉树的前序序列和中序序列分别存于两个一维数组中，试编写算法建立该二叉树的二叉链表
#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"

tree *fun_6_65(int mid[], int s1, int e1, int pre[], int s2, int e2)
{
	if (s1 <= e1 && s2 <= e2)
	{
		int i = 0;
		while (mid[s1 + i] != pre[s2] && s1 + i <= e1)
			i++;
		tree *node = (tree *)malloc(sizeof(tree));
		node->data = pre[s2];
		node->left = fun_6_65(mid, s1, s1 + i - 1, pre, s2 + 1, s2 + i);
		node->right = fun_6_65(mid, s1 + i + 1, e1, pre, s2 + i + 1, e2);
		return node;
	}
	else
	{
		return NULL;
	}
}

int main()
{
	/*******************code*******************/
	int pre[] = {1, 2, 3};
	int mid[] = {2, 1, 3};
	tree *root = fun_6_65(mid, 0, 2, pre, 0, 2);
	/******************************************/
	printf("\n\n****************************\n");
	printf("Press Enter key to continue\n");
	getchar();
	return 0;
	/******************************************/
}
